home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / xp-setup_v2140951202009.psc / class module / clsINI.cls < prev    next >
Text File  |  2009-01-18  |  4KB  |  105 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsINI"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Private mIniFileName As String
  16. Public valueygdibaca As String
  17.  
  18. Public Property Let FileName(ByVal INIFileName As String)
  19. Attribute FileName.VB_Description = "Set or Get the ini file name,required for working with the file"
  20.     If Dir(INIFileName, vbNormal) = "" Then
  21.       Open INIFileName For Output As #1
  22.       Close #1
  23.     End If
  24.     mIniFileName = INIFileName
  25. End Property
  26.  
  27. Public Property Get FileName() As String
  28.     FileName = mIniFileName
  29. End Property
  30.  
  31. Public Function GetValue(ByVal Section As String, ByVal Key As String, Optional ByVal DefaultValue As String) As String
  32. Attribute GetValue.VB_Description = "retrive the value of a key in a section"
  33.   On Error GoTo waduh_salah
  34.   Dim Value As String, X As Long
  35.   valueygdibaca = String$(500, 0)
  36.   X = GetPrivateProfileString(Section, Key, DefaultValue, valueygdibaca, Len(valueygdibaca), mIniFileName)
  37.   GetValue = Trim(Left(valueygdibaca, X))
  38.   hasilbacavalue = GetValue
  39. Exit Function
  40. waduh_salah:
  41.   GetValue = DefaultValue
  42. End Function
  43.  
  44. Public Function WriteValue(ByVal Section As String, ByVal Key As String, ByVal Value As String) As Boolean
  45. Attribute WriteValue.VB_Description = "Write the valueto the ini file"
  46.   On Error GoTo waduh_salah
  47.   Dim X As Integer
  48.   X = WritePrivateProfileString(Section, Key, Value, mIniFileName)
  49.   If X <> 0 Then WriteValue = True
  50.   Exit Function
  51. waduh_salah:
  52. End Function
  53.  
  54. Public Function GetAllSections() As Collection
  55. Attribute GetAllSections.VB_Description = "Retrive the list of section in the ini file"
  56.   Dim Value As String, retval As String, X As Integer
  57.   Dim S() As String, i As Integer
  58.   retval = String$(255, 0)
  59.   X = GetPrivateProfileString(vbNullString, "", "", retval, Len(retval), mIniFileName)
  60.   Value = Trim(Left(retval, X))
  61.   S = Split(Value, Chr(0))
  62.   Set GetAllSections = New Collection
  63.   With GetAllSections
  64.     For i = LBound(S) To UBound(S)
  65.       If S(i) <> "" Then .Add S(i)
  66.     Next
  67.   End With
  68. End Function
  69.  
  70. Public Function GetAllKeys(ByVal Section As String) As Collection
  71. Attribute GetAllKeys.VB_Description = "retrive all the key in the specified section"
  72.   Dim Value As String, retval As String, X As Integer
  73.   Dim S() As String, i As Integer
  74.   retval = String$(255, 0)
  75.   X = GetPrivateProfileString(Section, vbNullString, "", retval, Len(retval), mIniFileName)
  76.   Value = Trim(Left(retval, X))
  77.   S = Split(Value, Chr(0))
  78.   Set GetAllKeys = New Collection
  79.   With GetAllKeys
  80.     For i = LBound(S) To UBound(S)
  81.       If S(i) <> "" Then .Add S(i)
  82.     Next
  83.   End With
  84. End Function
  85.  
  86. Public Function DeleteSection(ByVal Section As String) As Boolean
  87. Attribute DeleteSection.VB_Description = "Delete all the keys in the specified section"
  88.   On Error GoTo waduh_salah
  89.   Dim X As Integer
  90.   X = WritePrivateProfileString(Section, vbNullString, "", mIniFileName)
  91.   If X <> 0 Then DeleteSection = True
  92.   Exit Function
  93. waduh_salah:
  94. End Function
  95.  
  96. Public Function DeleteKey(ByVal Section As String, ByVal Key As String) As Boolean
  97. Attribute DeleteKey.VB_Description = "Delete key in the ini file "
  98.   On Error GoTo waduh_salah
  99.   Dim X As Integer
  100.   X = WritePrivateProfileString(Section, Key, vbNullString, mIniFileName)
  101.   If X <> 0 Then DeleteKey = True
  102.   Exit Function
  103. waduh_salah:
  104. End Function
  105.